﻿Imports BITC.DatabaseManagement
Imports Microsoft.SqlServer.Management.Common
Imports Microsoft.SqlServer.Management.Smo

Public Class frmBackupDatabase

#Region "Declaration"
    Private _databaseName As String
    Private _server As Server
#End Region

#Region "Constructor"

#End Region

#Region "Property"

    Public Property DatabaseName() As String
        Get
            Return _databaseName
        End Get
        Set(ByVal value As String)
            _databaseName = value
        End Set
    End Property

    Public Property Server() As Server
        Get
            Return _server
        End Get
        Set(ByVal value As Server)
            _server = value
        End Set
    End Property

#End Region

#Region "Method"

#End Region

#Region "Event"

    Private Sub btnSaveFileLocation_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles btnSaveFileLocation.Click
        Try
            Dim result As Boolean = sfdBackup.ShowDialog()

            If result Then
                txtSaveFileLocation.Text = sfdBackup.FileName
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles btnOK.Click
        Try
            Me.Enabled = False
            SMOHelper.Current.BackupDatabase(_databaseName, txtSaveFileLocation.Text)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles btnCancel.Click
        Try
            DialogResult = DialogResult.Cancel
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

#End Region

End Class